﻿using System;
using EzDesk.Apps.Interface.Attendance;
using EzDesk.Apps.ServiceImpl.Attendance;
using EzDesk.Utility.TimerService;

namespace EzDesk.ServiceHost.TimerTask
{
    /// <summary>
    /// 每日最早的上班时间时，发送考勤统计信息给人事的Feed
    /// </summary>
    class DailyAttendanceStaticsTask : EverydayTimerTask
    {

        private readonly IAttendanceService _attendanceService = new AttendanceService();
        IAttendanceService AttendanceService
        {
            get { return _attendanceService; }
        }
        
        public DailyAttendanceStaticsTask()
            : base("DailyAttendanceStaticsTask")
        {
            TaskName = "DailyAttendanceStaticsTask";
            DayExecuteTime = GetSendTime();
        }

        public TimeSpan GetSendTime()
        {
            var attendanceConfig = AttendanceService.GetAttendanceConfig().Result;
            return attendanceConfig.StdOnDutyTime.ToDateTime().Add(-attendanceConfig.OnDutyOffsetForward).TimeOfDay;
        }


        protected sealed override void doExecute()
        {
            AttendanceService.SendDailyAttendanceStatics();
        }
    }
}
